package org.lex.swt;

import org.eclipse.jface.action.IAction;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;

public class SWTUtils {
	public static void setEnabled(boolean b, IAction... actions) {
		for (IAction a : actions) {
			a.setEnabled(b);
		}
	}

	public static void setWeight(SashForm sash, double weight) {
		Composite c = sash.getParent();
		if (null == c) {
			c = sash;
		}
		Point size = c.getSize();
		int or = sash.getOrientation();
		int max = Math.max(size.x, size.y);
		if (SWT.VERTICAL == or) {
			max = size.y;
		} else {
			max = size.x;
		}
		int a = (int) (weight * max);
		int b = max - a;
		int[] weights = { a, b };
		System.out.println("max=" + max + " weights=[" + a + ", " + b + "]");
		sash.setWeights(weights);
	}
}
